
function rInitIndex(n) {
	var ns = Array.from(new Array(n), v => {
		return new Array(n)
	});
	var sqn = Math.floor(Math.sqrt(n));
	for (let index = 0, len = n; index < len; index++) {
		for (let jindex = 0, len = n; jindex < len; jindex++) {
			if (jindex == index) {
				ns[index][jindex] = 0;
				continue;
			}

			var indexX = index % sqn;
			var jindexX = jindex % sqn;
			
			var indexY = (index - indexX) / sqn + 1;
			
			var jindexY = (jindex - jindexX) / sqn + 1;
			if ((indexX - jindexX) % sqn == 1 || (indexY - jindexY) % sqn == 1) {
				ns[index][jindex] = 1
				ns[jindex][index] = 1
			} else {
				ns[index][jindex] = 0
				ns[jindex][index] = 0
			}
		}
	}
	return ns;
}
console.log( rInitIndex(10).join("\n"))
module.exports = { rInitIndex }